package org.exteen.tag.core;

import org.exteen.ExteenException;
import org.exteen.exec.ExteenContext;
import org.exteen.exec.ExteenPathChangeException;
import org.exteen.exec.Tag;
import org.exteen.output.ExteenStream;
import org.exteen.parser.Attr;

public class WhenTag extends Tag {

    public void doTag(ExteenContext ctx, ExteenStream stream) {
        if (!(ctx.getParent().getTagMark() instanceof ChooseTag)) {
            throw new ExteenException("Tag when must be placed inside choose tag");
        }
        Object value = null;
        for (Attr a: ctx.getNode().getAttributes()) {
            if ("test".equals(a.getKey())) {
                value = a.getValue(ctx);
                break;
            }
        }
        if (Boolean.TRUE.equals(value)) {
            super.doTag(ctx, stream);
            throw new ExteenPathChangeException(ExteenPathChangeException.Type.BREAK);
        }
    }
}